# # 在脚本开头添加编码声明
# [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# $OutputEncoding = [System.Text.Encoding]::UTF8

# 删除操作前检查文件是否存在
$pathsToDelete = @(
    "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/gateway/oj-gateway.jar",
    "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/friend/oj-friend.jar",
    "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/job/oj-job.jar",
    "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/judge/oj-judge.jar",
    "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/system/oj-system.jar"
)

foreach ($path in $pathsToDelete) {
    if (Test-Path $path) {
        Remove-Item $path -ErrorAction SilentlyContinue
        Write-Host "deleted: $path"
    } else {
        Write-Host "file no exits, skip delete: $path"
    }
}

# 复制操作
$copyOperations = @(
    @{
        Source = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/oj-gateway/target/oj-gateway-1.0-SNAPSHOT.jar"
        Destination = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/gateway/oj-gateway.jar"
    },
    @{
        Source = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/oj-modules/oj-judge/target/oj-judge-1.0-SNAPSHOT.jar"
        Destination = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/judge/oj-judge.jar"
    },
    @{
        Source = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/oj-modules/oj-friend/target/oj-friend-1.0-SNAPSHOT.jar"
        Destination = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/friend/oj-friend.jar"
    },
    @{
        Source = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/oj-modules/oj-job/target/oj-job-1.0-SNAPSHOT.jar"
        Destination = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/job/oj-job.jar"
    },
    @{
        Source = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/oj-modules/oj-system/target/oj-system-1.0-SNAPSHOT.jar"
        Destination = "D:/SoftwareContentStorageLocation/code/java/snowdragon-online-judge/deploy/test/sdoj-jar/system/oj-system.jar"
    }
)

foreach ($operation in $copyOperations) {
    $source = $operation.Source
    $destination = $operation.Destination

    # 确保目标目录存在
    $destDir = [System.IO.Path]::GetDirectoryName($destination)
    if (-not (Test-Path $destDir)) {
        New-Item -ItemType Directory -Path $destDir -Force | Out-Null
    }

    if (Test-Path $source) {
        Copy-Item $source $destination -Force
        Write-Host "copied: $source to $destination"
    } else {
        Write-Host "source file no exits, skip copy: $source"
    }
}

pause